﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace libVNEditor
{
    public partial class CharacterManagerForm : Form
    {
        public CharacterManagerForm()
        {
            InitializeComponent();
        }

        public void RefreshForm()
        {
            listBox_characters.Items.Clear();
            foreach(Character c in Program.mainform.Plot.characters)
            {
                listBox_characters.Items.Add(c.name);
            }
        }

        private void CharacterManagerForm_Load(object sender, EventArgs e)
        {
            RefreshForm();
        }

        private void OnAddClick(object sender, EventArgs e)
        {
            string _name = Interaction.InputBox("请输入新的角色名:", "创建新角色" );
            if(_name == "")
            {
                MessageBox.Show("角色名不能为空！");
                return;
            }
            else
            {
                Character c = new Character { name = _name };
                Program.mainform.Plot.characters.Add(c);
                RefreshForm();
            }
        }

        private void OnDelClick(object sender, EventArgs e)
        {
            int idx = listBox_characters.SelectedIndex;
            if (idx == -1) return;
            else
            {
                if (MessageBox.Show(string.Format("确定要删除角色 {0} 吗？", Program.mainform.Plot.characters[idx].name), "删除角色", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Program.mainform.Plot.characters.RemoveAt(idx);
                    RefreshForm();
                }
            }
        }
    }
}
